package top.lixunda.ecommerce.server.good.api.entity.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import top.lixunda.common.utils.ObjectValidators;
import top.lixunda.ecommerce.server.good.api.entity.db.PageInfoShowDO;

/**
 * 前端主页Featured数据VO
 *
 * @author lixunda
 * @version time:2020/3/20 16:25
 */
@ApiModel("前端主页Featured数据VO")
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class PageFeaturedVO {

    /**
     * 数据主键编号
     */
    @ApiModelProperty("数据主键编号")
    private Integer id;

    @ApiModelProperty("大标题")
    private String title;

    @ApiModelProperty("小标题")
    private String subTitle;

    @ApiModelProperty("图片")
    private String image;

    @ApiModelProperty("图片文件编号")
    private Integer imageFileId;

    @ApiModelProperty("商品编号")
    private Integer linkGoodId;

    @ApiModelProperty("商品详细数据")
    private GoodConvertVO linkGood;

    @ApiModelProperty("展示方式，LEFT RIGHT")
    private String direction;

    @ApiModelProperty("位置")
    private String position;

    /**
     * 转换数据
     *
     * @param pageInfoShowDO 页面信息数据
     * @param goodConvertVO  商品详细信息
     * @return PageFeaturedVO
     * @see top.lixunda.ecommerce.server.good.api.entity.dto.PageIndexFeaturedInsertDTO
     */
    public static PageFeaturedVO fromPageInfoShowDO(PageInfoShowDO pageInfoShowDO, GoodConvertVO goodConvertVO) {
        if (ObjectValidators.isEmpty(pageInfoShowDO)) {
            return null;
        }
        return new PageFeaturedVO()
                .setId(pageInfoShowDO.getId())
                .setPosition(pageInfoShowDO.getPosition())
                .setImage(pageInfoShowDO.getImage1())
                .setImageFileId(pageInfoShowDO.getImageFile1())
                .setLinkGoodId(Integer.valueOf(pageInfoShowDO.getLink()))
                .setLinkGood(goodConvertVO)
                .setTitle(pageInfoShowDO.getContent1())
                .setSubTitle(pageInfoShowDO.getContent2())
                .setDirection(pageInfoShowDO.getContent3());
    }

}
